/**** Geometry Shader Marching Cubes Example
	* Copyright Cyril Crassin, January 2007.
	* This code is partially based on the example of 
	* Paul Bourk "Polygonising a scalar field" located at :
	* http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise/
****/

#ifndef GLEngineApp_h
#define GLEngineApp_h

#include <vector>

#include "AbstractClass.h"
//#include "MarchingCubes.h"
//class Terrain;
//class QuadTree;

//Alex stuff
class RenderComponent;
class VertexColorCube;
//class ObjModel;
#include "Utils\mathlib.h"

class Model;
class GLSLShader;
class ColorShader;
class BrickShader;

class GLEngineApp : public AbstractClass {

public:

	GLEngineApp(const char *title, int w, int h, int flags = 0);
	GLEngineApp(int *argcp, char **argv, const char *title, int w, int h, int flags = 0);

protected:
	virtual void Reshape(int w, int h);
	virtual void Keyboard(unsigned char key);
	virtual void Mouse(int button, int state, int x, int y);
	virtual void MouseMove(int x, int y);
	virtual void MousePassiveMove(int x, int y);

	virtual void Idle() ;
	virtual void Display() ;

	virtual void Init();
	virtual void Update(int value);

private:
	//Private Functions
	GLuint LoadBMP(char *Filename);

	//Terrain* m_pTerrain;
	//QuadTree* m_pQuadTree;

	float zoom;
    float rotx;
    float roty;
    float tx;
    float ty;
    int lastx;
    int lasty;
    unsigned char Buttons[3];

    float offset;

	//Private Data members
	GLuint m_Texture[1];
	GLfloat m_LightAmbient[4];
	GLfloat m_LightDiffuse[4];
	GLfloat m_LightPosition[4];
	

	GLuint	m_Filter;	
	//Mouse control
	Vector2i oldMousePos;
	bool mouseButtons[3];

	Vector3f sphereLightPos;
	Vector3f viewOrient;


	//general flags
	bool pause;
	bool wireframe;

	//GLSL
	GLhandleARB programObject;
	GLhandleARB programObjectGS;
	GLhandleARB programObjectFS;

	GLuint edgeTableTex;
	GLuint triTableTex;

	GLuint dataFieldTex[3];

	Vector3f cubeSize;
	Vector3f cubeStep;

	Vector3i dataSize;

	float *dataField[3];
	float isolevel;

	bool animate;
	bool autoWay;
	bool enableVBO;
	bool enableSwizzledWalk;

	int mode;

	int curData;

	float *gridData;
	GLuint gridDataBuffId;
	GLuint gridDataSwizzledBuffId;

	float m_Rotation;

	//Alex Stuff
	//Grid
	void CreateGridVA(int nrOfLines, float gridSize);
	void DrawGridVA();

	BrickShader* m_pBrickShader;
	ColorShader* m_pColorShader;

	vertexcolor* m_pGridData;

	// Lijst waar alle render components insteken en dus automatisch gerenderd worden.
    std::vector<RenderComponent*> m_RenderComponents;

	//ObjModel* m_pMyModel;
	Model* m_pWeapon;
};

#endif
